Tofte-Taplin stack-based algorithm